﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载程序集
            Assembly ass = Assembly.Load("MyModel");
            //创建实例
            object instance = ass.CreateInstance("MyModel.SList");
            object student = ass.CreateInstance("MyModel.StudentModel");
            //获取类型
            Type t = instance.GetType();
            Type[] ts = t.GetGenericArguments();
            //获取所有属性
            PropertyInfo[] prop = student.GetType().GetProperties();
            //获取slist字段
            FieldInfo field = t.GetField("slist");
            //不知道这是怎么用
            object c = CreateGeneric(typeof(List<>), student.GetType());
            int i = 0;
            do
            {
                Console.WriteLine("请输入要查询的人：按0退出");
                string serch = Console.ReadLine();
                if (serch == i.ToString())
                {
                    i = -1;
                }

            } while (i == 0);
        }
        static object CreateGeneric(Type generic, Type innerType, params object[] args)
        {
            Type specificType = generic.MakeGenericType(new System.Type[] { innerType });
            return Activator.CreateInstance(specificType, args);
        }
        //网上找的反射重构的泛型
        //public static object CreateGeneric(Type generic, Type innerType, params object[] args)
        //{
        //    Type specificType = generic.MakeGenericType(new System.Type[] { innerType });
        //    return Activator.CreateInstance(specificType, args);
        //}
        //object genericList = CreateGeneric(typeof(List<>), typeof(EC));

    }
}
